const httpRequest = 'http://58.59.114.54:10006/';
const httpRequestJmas = 'https://www.zwfw.hlj.gov.cn/';
// http://58.59.114.54/opac/advance/search
import axios from 'axios'
import qs from 'qs'
const service = {
	requestJMAS: function ({
		interface_id,
		app_id,
		params = {}
	}) {
		return new Promise((resolve) => {
			const baseParams = {
				version: '1.0',
				charset: 'UTF-8',
				origin: '1',
				timestamp: new Date().getTime(),
				interface_id,
				app_id,
				biz_content: JSON.stringify(params),
			}
			axios({
				url: `${httpRequestJmas}jpaas-jags-server/interface/createsign.do`,
				method: 'POST',
				data: qs.stringify(baseParams),
			}).then(res => {
				const sign = res.data.data.sign
				axios({
					url: `${httpRequestJmas}jpaas-jags-server/interface/gateway.do`,
					method: 'POST',
					data: qs.stringify({
						sign,
						...baseParams
					}),
				}).then(res => {
					resolve(res)
				})
			})
		})
	},
	//请求token
	requestToken(data) {
		return new Promise((resolve, reject) => {
			axios({
				url: `${httpRequest}openlib/service/barcode/token`,
				method: 'POST',
				data: qs.stringify(data),
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},
			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//请求当前借阅
	requestCurrent(data) {
		return new Promise((resolve, reject) => {
			window.lightAppJssdk.request.request({
				url: `${httpRequest}openlib/service/barcode/rdloanlist`,
				method: 'POST',
				data: qs.stringify(data),
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				},

			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//历史借阅
	requestHistory(data) {
		return new Promise((resolve, reject) => {
			window.lightAppJssdk.request.request({
				url: `${httpRequest}openlib/service/barcode/historyloan`,
				method: 'POST',
				data: qs.stringify(data)

			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//检索
	requestSearchList(data) {
		return new Promise((resolve, reject) => {
			window.lightAppJssdk.request.request({
				url: `http://58.59.114.54/opac/advance/search`,
				method: 'POST',
				data: qs.stringify(data)

			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//检索详情
	requestDeail(data) {
		return new Promise((resolve, reject) => {
			axios({
				url: `http://58.59.114.54/opac/api/book/${data}`,

			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	requestAppointmentTime(addrid) {
		return new Promise((resolve, reject) => {
			axios({
				//appointment/date_query_filter.do
				url: `${httpRequest}appointment/date_query.do?addrid=${addrid}`,
			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//续借
	requestContinue(data) {
		return new Promise((resolve, reject) => {
			axios({
				url: `${httpRequest}openlib/service/barcode/renewbook`,
				method: 'POST',
				data: qs.stringify(data)

			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//请求月份
	requestMonths() {
		return new Promise((resolve, reject) => {
			axios({
				url: `http://117.132.12.45:8088/zhqgzxt/interfaces/salary/monthlist.do`,
				method: 'POST',
			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
	//请求工资详情
	requestSalary(data) {
		return new Promise((resolve, reject) => {
			axios({
				url: `http://117.132.12.45:8088/zhqgzxt/interfaces/salary/personsalary.do`,
				method: 'POST',
				data: qs.stringify(data)
			}).then(res => {
				resolve(res)
			}).catch(err => {
				reject(err)
			})
		})
	},
}
export default service

export { httpRequestJmas }
